/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * frmListados.java
 *
 * Created on 20/02/2011, 08:56:32 AM
 */
package Principal;

import javax.swing.JTable;
import javax.swing.table.DefaultTableModel;


/**
* This code was edited or generated using CloudGarden's Jigloo
* SWT/Swing GUI Builder, which is free for non-commercial
* use. If Jigloo is being used commercially (ie, by a corporation,
* company or business for any purpose whatever) then you
* should purchase a license for each developer using Jigloo.
* Please visit www.cloudgarden.com for details.
* Use of Jigloo implies acceptance of these licensing terms.
* A COMMERCIAL LICENSE HAS NOT BEEN PURCHASED FOR
* THIS MACHINE, SO JIGLOO OR THIS CODE CANNOT BE USED
* LEGALLY FOR ANY CORPORATE OR COMMERCIAL PURPOSE.
*/
public class frmListados extends javax.swing.JFrame {

	/** Creates new form frmListados */
	public frmListados() {
		initComponents();
	}

	/**
	 * This method is called from within the constructor to initialize the form.
	 * WARNING: Do NOT modify this code. The content of this method is always
	 * regenerated by the Form Editor.
	 */
	@SuppressWarnings("unchecked")
	// <editor-fold defaultstate="collapsed"
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jScrollPane1 = new javax.swing.JScrollPane();
        tabla = new javax.swing.JTable();
        btnListarCedula = new javax.swing.JButton();
        btnNotaFinal = new javax.swing.JButton();
        btnAprobados = new javax.swing.JButton();
        btnReprobados = new javax.swing.JButton();
        btnSalir = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        getContentPane().setLayout(null);

        tabla.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null}
            },
            new String [] {
                "Nombre", "Apellido", "Cedula", "Nota Final"
            }
        ));
        jScrollPane1.setViewportView(tabla);

        getContentPane().add(jScrollPane1);
        jScrollPane1.setBounds(10, 10, 510, 300);

        btnListarCedula.setText("Ordenar por Cedula");
        btnListarCedula.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnListarCedulaActionPerformed(evt);
            }
        });
        getContentPane().add(btnListarCedula);
        btnListarCedula.setBounds(20, 330, 150, 40);

        btnNotaFinal.setText("Ordenar por Nota Final");
        btnNotaFinal.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnNotaFinalActionPerformed(evt);
            }
        });
        getContentPane().add(btnNotaFinal);
        btnNotaFinal.setBounds(190, 330, 180, 40);

        btnAprobados.setText("Aprobados");
        btnAprobados.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnAprobadosActionPerformed(evt);
            }
        });
        getContentPane().add(btnAprobados);
        btnAprobados.setBounds(20, 380, 150, 40);

        btnReprobados.setText("Reprobados");
        btnReprobados.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnReprobadosActionPerformed(evt);
            }
        });
        getContentPane().add(btnReprobados);
        btnReprobados.setBounds(190, 380, 180, 40);

        btnSalir.setText("Salir");
        btnSalir.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnSalirActionPerformed(evt);
            }
        });
        getContentPane().add(btnSalir);
        btnSalir.setBounds(390, 330, 120, 40);

        java.awt.Dimension screenSize = java.awt.Toolkit.getDefaultToolkit().getScreenSize();
        setBounds((screenSize.width-546)/2, (screenSize.height-476)/2, 546, 476);
    }// </editor-fold>//GEN-END:initComponents

	private void btnListarCedulaActionPerformed(java.awt.event.ActionEvent evt) {// GEN-FIRST:event_btnListarCedulaActionPerformed
		// TODO add your handling code here:
		for (int e = 0; e < frmInicial.seccion.getEstudiantes().size(); e++) {
			tabla.setValueAt("", e, 0);
			tabla.setValueAt("", e, 1);
			tabla.setValueAt("", e, 2);
			tabla.setValueAt("", e, 3);
		}
		frmInicial.seccion.ListarEstudiantesCedula();

		for (int i = 0; i < frmInicial.seccion.getEstudiantes().size(); i++) {
			tabla.setValueAt(frmInicial.seccion.getEstudiantes().elementAt(i)
					.getNombre(), i, 0);
			tabla.setValueAt(frmInicial.seccion.getEstudiantes().elementAt(i)
					.getApellido(), i, 1);
			tabla.setValueAt(frmInicial.seccion.getEstudiantes().elementAt(i)
					.getCedula(), i, 2);
			tabla.setValueAt(frmInicial.seccion.getEstudiantes().elementAt(i)
					.getNotaFinal(), i, 3);
		}
	}// GEN-LAST:event_btnListarCedulaActionPerformed

	private void btnNotaFinalActionPerformed(java.awt.event.ActionEvent evt) {// GEN-FIRST:event_btnNotaFinalActionPerformed
		// TODO add your handling code here:
		for (int e = 0; e < frmInicial.seccion.getEstudiantes().size(); e++) {
			tabla.setValueAt("", e, 0);
			tabla.setValueAt("", e, 1);
			tabla.setValueAt("", e, 2);
			tabla.setValueAt("", e, 3);
		}
		frmInicial.seccion.ListarEstudiantesNota();

		for (int i = 0; i < frmInicial.seccion.getEstudiantes().size(); i++) {
			tabla.setValueAt(frmInicial.seccion.getEstudiantes().elementAt(i)
					.getNombre(), i, 0);
			tabla.setValueAt(frmInicial.seccion.getEstudiantes().elementAt(i)
					.getApellido(), i, 1);
			tabla.setValueAt(frmInicial.seccion.getEstudiantes().elementAt(i)
					.getCedula(), i, 2);
			tabla.setValueAt(frmInicial.seccion.getEstudiantes().elementAt(i)
					.getNotaFinal(), i, 3);
		}
	}// GEN-LAST:event_btnNotaFinalActionPerformed

	private void btnAprobadosActionPerformed(java.awt.event.ActionEvent evt) {// GEN-FIRST:event_btnAprobadosActionPerformed
		// TODO add your handling code here:
		for (int e = 0; e < frmInicial.seccion.getEstudiantes().size(); e++) {
			tabla.setValueAt("", e, 0);
			tabla.setValueAt("", e, 1);
			tabla.setValueAt("", e, 2);
			tabla.setValueAt("", e, 3);
		}
		frmInicial.seccion.ListarAprobados();
		int indice = 0;
		for (int i = 0; i < frmInicial.seccion.getEstudiantes().size(); i++) {
			if (frmInicial.seccion.getEstudiantes().elementAt(i).getNotaFinal() > 10) {
				tabla.setValueAt(
						frmInicial.seccion.getEstudiantes().elementAt(i)
								.getNombre(), indice, 0);
				tabla.setValueAt(
						frmInicial.seccion.getEstudiantes().elementAt(i)
								.getApellido(), indice, 1);
				tabla.setValueAt(
						frmInicial.seccion.getEstudiantes().elementAt(i)
								.getCedula(), indice, 2);
				tabla.setValueAt(
						frmInicial.seccion.getEstudiantes().elementAt(i)
								.getNotaFinal(), indice, 3);
				indice++;
			}

		}
	}// GEN-LAST:event_btnAprobadosActionPerformed

	private void btnReprobadosActionPerformed(java.awt.event.ActionEvent evt) {// GEN-FIRST:event_btnReprobadosActionPerformed
		// TODO add your handling code here:
		for (int e = 0; e < frmInicial.seccion.getEstudiantes().size(); e++) {
			tabla.setValueAt("", e, 0);
			tabla.setValueAt("", e, 1);
			tabla.setValueAt("", e, 2);
			tabla.setValueAt("", e, 3);
		}
		frmInicial.seccion.ListarReprobados();
		int indice = 0;
		for (int i = 0; i < frmInicial.seccion.getEstudiantes().size(); i++) {
			if (frmInicial.seccion.getEstudiantes().elementAt(i).getNotaFinal() < 10) {
				tabla.setValueAt(
						frmInicial.seccion.getEstudiantes().elementAt(i)
								.getNombre(), indice, 0);
				tabla.setValueAt(
						frmInicial.seccion.getEstudiantes().elementAt(i)
								.getApellido(), indice, 1);
				tabla.setValueAt(
						frmInicial.seccion.getEstudiantes().elementAt(i)
								.getCedula(), indice, 2);
				tabla.setValueAt(
						frmInicial.seccion.getEstudiantes().elementAt(i)
								.getNotaFinal(), indice, 3);
				indice++;

			}
		}

	}// GEN-LAST:event_btnReprobadosActionPerformed

	private void btnSalirActionPerformed(java.awt.event.ActionEvent evt) {// GEN-FIRST:event_btnSalirActionPerformed
		// TODO add your handling code here:
		dispose();
	}// GEN-LAST:event_btnSalirActionPerformed

	/**
	 * @param args
	 *            the command line arguments
	 */
	public static void main(String args[]) {
		java.awt.EventQueue.invokeLater(new Runnable() {

			public void run() {
				new frmListados().setVisible(true);
			}
		});
	}

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnAprobados;
    private javax.swing.JButton btnListarCedula;
    private javax.swing.JButton btnNotaFinal;
    private javax.swing.JButton btnReprobados;
    private javax.swing.JButton btnSalir;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTable tabla;
    // End of variables declaration//GEN-END:variables
}
